<template>
  <el-form-item :label="itemObj.label" v-if="itemObj.type=='input'" :prop="itemObj.prop"  :rules="itemObj.required?itemObj.rules:[]">
    <el-input v-model="ruleForm[itemObj.key]" clearable placeholder=""/>
  </el-form-item>
  <el-form-item :label="itemObj.label" v-else-if="itemObj.type=='select'" :prop="itemObj.prop">
    <el-select v-model="ruleForm[itemObj.key]" clearable placeholder="请选择">
        <el-option
          v-for="(item,i) in itemObj.options"
          :key="i"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
  </el-form-item>
  <el-form-item :label="itemObj.label" v-else-if="itemObj.type=='uploade'" :prop="itemObj.prop">
    <el-upload
      class="upload-demo"
      style="position:relative"
      :action="httpUrl+get_branch+'/ht-user/user/upload'"
      :headers="headers"
      :on-preview="handlePreview"
      :on-remove="handleRemove"
      :before-remove="beforeRemove"
      :on-success="onSuccess"
      multiple
      :limit="1"
      :on-exceed="handleExceed"
      :file-list="fileList"
    >
      <el-button size="small">点击上传</el-button>
      <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
    </el-upload>
  </el-form-item>
  <el-form-item :label="itemObj.label" v-else-if="itemObj.type=='textarea'" :prop="itemObj.prop">
    <el-input v-model="ruleForm[itemObj.key]" />
  </el-form-item>
  <el-form-item :label="itemObj.label" v-else-if="itemObj.type=='status'" :prop="itemObj.prop">
    <el-radio-group v-model="ruleForm[itemObj.key]">
      <el-radio label="0">正常</el-radio>
      <el-radio label="1">禁用</el-radio>
    </el-radio-group>
  </el-form-item>
</template>

<script>
import { getToken } from '@/utils/auth'

export default {
  props:{
    ruleForm:{
      type:Object,
      require:true,
      default:()=>{
        return {}
      }
    },
    itemObj:{
      type:Object,
      require:true,
      default:()=>{
        return {}
      }
    }
  },
  data() {
    return {
      httpUrl: process.env.VUE_APP_BASE_API,
      fileList:[],
      headers: {
        Authorization: 'bearer ' + getToken()
      },
    }
  },
  created() {
  },
  methods: {
    onSuccess(v) {
    },
    handleRemove(file, fileList) {
    },
    handlePreview(file) {
    },
    handleExceed(files, fileList) {
      // this.$message.warning(`当前限制选择1个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
    },
    beforeRemove(file, fileList) {
      // return this.$confirm(`确定移除 ${file.name}？`)
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          
        } else {
          return false
        }
      })
    },
   
    setVal(v, depList, postList) {
      this.options2 = postList
      this.options = depList
      this.title = v == 'add' ? '新增' : '修改'
      this.btnStr = v == 'add' ? '立即创建' : '修改'

      if (v != 'add') {
        // this.ruleForm = JSON.parse(v)
        // this.ruleForm.sex = this.ruleForm.sex + ''
        // this.ruleForm.status = this.ruleForm.status + ''
      } else {
        // this.resetForm()
      }
      this.dialogTableVisible = true
    }
  }
}
</script>

<style lang="scss" scoped>
>>>.el-select{
  width:100%;
}
>>>.el-upload-list{
    position:absolute !important;
    left:100px !important;
    top:-6px !important;
}
.el-form{
    display:flex;
    flex-direction:row;
    flex-wrap:wrap;
    .el-form-item{
        width:50%;
    }
}
</style>
